<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="关联订单" prop="orderId">
        <el-input
          v-model="queryParams.orderId"
          placeholder="请输入关联订单"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="申诉提交时间">
        <el-date-picker
          v-model="daterangeSubmitTime"
          style="width: 240px"
          value-format="yyyy-MM-dd"
          type="daterange"
          range-separator="-"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
        ></el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['order:complaint:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['order:complaint:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['order:complaint:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['order:complaint:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="complaintList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="申诉ID" align="center" prop="complaintId" />
      <el-table-column label="关联订单" align="center" prop="orderId" />
      <el-table-column label="乘客ID" align="center" prop="passengerId" />
      <el-table-column label="司机ID" align="center" prop="driverId" />
      <el-table-column label="申诉提交时间" align="center" prop="submitTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.submitTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="申诉原因" align="center" prop="complaintReason" />
      <el-table-column label="处理类型：充值、扣款、补发优惠券等" align="center" prop="handleType" />
      <el-table-column label="处理结果：待审核、已处理等" align="center" prop="handleResult" />
      <el-table-column label="处理方案描述" align="center" prop="handleScheme" />
      <el-table-column label="调账前金额" align="center" prop="beforeAdjust" />
      <el-table-column label="调账后金额" align="center" prop="afterAdjust" />
      <el-table-column label="当前状态：待审核、已完成" align="center" prop="status" />
      <el-table-column label="处理时间" align="center" prop="operateTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.operateTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="处理人" align="center" prop="operator" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['order:complaint:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['order:complaint:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改疑义账单列表对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="关联订单" prop="orderId">
          <el-input v-model="form.orderId" placeholder="请输入关联订单" />
        </el-form-item>
        <el-form-item label="乘客ID" prop="passengerId">
          <el-input v-model="form.passengerId" placeholder="请输入乘客ID" />
        </el-form-item>
        <el-form-item label="司机ID" prop="driverId">
          <el-input v-model="form.driverId" placeholder="请输入司机ID" />
        </el-form-item>
        <el-form-item label="申诉提交时间" prop="submitTime">
          <el-date-picker clearable
            v-model="form.submitTime"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择申诉提交时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="申诉原因" prop="complaintReason">
          <el-input v-model="form.complaintReason" placeholder="请输入申诉原因" />
        </el-form-item>
        <el-form-item label="处理结果：待审核、已处理等" prop="handleResult">
          <el-input v-model="form.handleResult" placeholder="请输入处理结果：待审核、已处理等" />
        </el-form-item>
        <el-form-item label="处理方案描述" prop="handleScheme">
          <el-input v-model="form.handleScheme" placeholder="请输入处理方案描述" />
        </el-form-item>
        <el-form-item label="调账前金额" prop="beforeAdjust">
          <el-input v-model="form.beforeAdjust" placeholder="请输入调账前金额" />
        </el-form-item>
        <el-form-item label="调账后金额" prop="afterAdjust">
          <el-input v-model="form.afterAdjust" placeholder="请输入调账后金额" />
        </el-form-item>
        <el-form-item label="处理时间" prop="operateTime">
          <el-date-picker clearable
            v-model="form.operateTime"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择处理时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="处理人" prop="operator">
          <el-input v-model="form.operator" placeholder="请输入处理人" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listComplaint, getComplaint, delComplaint, addComplaint, updateComplaint } from "@/api/order/complaint"

export default {
  name: "Complaint",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 疑义账单列表表格数据
      complaintList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 处理人时间范围
      daterangeSubmitTime: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        orderId: null,
        submitTime: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    }
  },
  created() {
    this.getList()
  },
  methods: {
    /** 查询疑义账单列表列表 */
    getList() {
      this.loading = true
      this.queryParams.params = {}
      if (null != this.daterangeSubmitTime && '' != this.daterangeSubmitTime) {
        this.queryParams.params["beginSubmitTime"] = this.daterangeSubmitTime[0]
        this.queryParams.params["endSubmitTime"] = this.daterangeSubmitTime[1]
      }
      listComplaint(this.queryParams).then(response => {
        this.complaintList = response.rows
        this.total = response.total
        this.loading = false
      })
    },
    // 取消按钮
    cancel() {
      this.open = false
      this.reset()
    },
    // 表单重置
    reset() {
      this.form = {
        complaintId: null,
        orderId: null,
        passengerId: null,
        driverId: null,
        submitTime: null,
        complaintReason: null,
        handleType: null,
        handleResult: null,
        handleScheme: null,
        beforeAdjust: null,
        afterAdjust: null,
        status: null,
        operateTime: null,
        operator: null
      }
      this.resetForm("form")
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1
      this.getList()
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.daterangeSubmitTime = []
      this.resetForm("queryForm")
      this.handleQuery()
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.complaintId)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset()
      this.open = true
      this.title = "添加疑义账单列表"
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset()
      const complaintId = row.complaintId || this.ids
      getComplaint(complaintId).then(response => {
        this.form = response.data
        this.open = true
        this.title = "修改疑义账单列表"
      })
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.complaintId != null) {
            updateComplaint(this.form).then(response => {
              this.$modal.msgSuccess("修改成功")
              this.open = false
              this.getList()
            })
          } else {
            addComplaint(this.form).then(response => {
              this.$modal.msgSuccess("新增成功")
              this.open = false
              this.getList()
            })
          }
        }
      })
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const complaintIds = row.complaintId || this.ids
      this.$modal.confirm('是否确认删除疑义账单列表编号为"' + complaintIds + '"的数据项？').then(function() {
        return delComplaint(complaintIds)
      }).then(() => {
        this.getList()
        this.$modal.msgSuccess("删除成功")
      }).catch(() => {})
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('order/complaint/export', {
        ...this.queryParams
      }, `complaint_${new Date().getTime()}.xlsx`)
    }
  }
}
</script>
